import ecitys.gcs.*
import org.hibernate.criterion.DetachedCriteria
import org.hibernate.criterion.Projections
import org.hibernate.criterion.Subqueries

def c = ValorIndice.createCriteria()

def r = c.get{
        projections{
            max('dataDeVigencia')
        }
}
println r

//def d = ValorIndice.createCriteria()
//def s = d.get{
def h= ValorIndice.withCriteria{
        def sub = DetachedCriteria.forClass(ValorIndice, 'vi').with{
                  setProjection(Projections.max('vi.dataDeVigencia'));  
                  //d.add(Subqueries.propertyEq('dataDeVigencia',sub))
        }

        projections{
            property('valor')
        }
        //eq('dataDeVigencia',r)
        instance.add(Subqueries.propertyEq('dataDeVigencia',sub))
}
println h.get(0)